package rs.dalao.syc.user.all.service.impl;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Service;
import rs.dalao.syc.common.pojo.authentication.CurrentPrincipal;
import rs.dalao.syc.common.response.JsonResult;
import rs.dalao.syc.user.all.dao.persist.repository.IUserRepository;
import rs.dalao.syc.user.all.pojo.entity.User;
import rs.dalao.syc.user.all.pojo.param.UserUpdateParam;
import rs.dalao.syc.user.all.pojo.vo.UserInfoUpdateVO;
import rs.dalao.syc.user.all.service.IUserService;

import java.io.File;

@Service
public class IUserServiceImpl implements IUserService {
    @Autowired
    private IUserRepository userRepository;

    //更新用户的头像，昵称信息
    @Override
    public int updateUserInfo(UserUpdateParam userUpdateParam,Long id) {
        //判断出否需要更换头像
        if(userUpdateParam.getAvatar()!=null){
            //得到原图片的路径
            String imgUrl = userRepository.getAvatar(id);
            //删除对应的图片文件
            new File(imgUrl).delete();
        }

        return userRepository.update(userUpdateParam,id);
    }
}
